<?php 
/**
 * 类型控制器
 */
class TypeController extends AuthController{
	private $model;
    /**
     * 类型管理控制器
     */
    public function __auto(){
	    $this->model = K('Type');
	}
     
     
    public function index(){
    	//遍历Category所有数据
    	$data = $this->model->all();
		//分配数据
		$this->assign('data',$data);
        $this->display(); 
    }
	
	public function add(){
		if(IS_POST){
			if(!$this->model->addDate()){
				$this->error($this->model->error);
			}
			$this->success('添加类型成功', U('index'));
		}
	    $this->display();
	}
	
	public function edit(){
		$tid = Q('get.tid',0,'intval');
		if(IS_POST){
			if(!$this->model->editDate($tid)){
				$this->error($this->model->error);
			}
			$this->success('修改成功', U('index'));
		}
		//获得旧数据
		$oldData = $this->model->where("tid={$tid}")->find();
		$this->assign('oldData',$oldData);
		
	    $this->display();
	}
	
	
	/**
	 * 删除
	 */
	public function del(){
	    $tid = Q('get.tid',0,'intval');
		//删除类型
		$this->model->where("tid={$tid}")->delete();
		//删除对应属性
		$attr = K('Attr');
		$attr->where("type_tid={$tid}")->delete();
		//1.提示信息 2.跳转地址 3.跳转时间
		$this->success('删除成功',U('index'),1);	
	}
	
 }
 
 
 
 
 
 
 
 
 
 
 



 ?>